home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3028 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  48 lines

  1. Path: crl.crl.com!not-for-mail
  2. From: bobfry@crl.com (Robert Fry)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is it possible to #include <#defined or -D 'ed macro>?
  5. Date: 25 Jan 1996 08:32:45 -0800
  6. Organization: CRL Dialup Internet Access
  7. Message-ID: <4e8bbd$nl7@crl.crl.com>
  8. References: <5rbuntgqp0.fsf@ritz.mordor.com>
  9. NNTP-Posting-Host: crl.com
  10.  
  11. benjamin@ritz.mordor.com (Joseph Thomas) writes:
  12.  
  13. >Does anyone know a way of having an include statement that can include
  14. >a file, based on a -D <MACRO_NAME> flag passed to the compiler, to
  15. >give the effect of:
  16.  
  17. >#include <SOURCE>
  18.  
  19. >cc -D SOURCE=source_a.h
  20.  
  21. >includes source_a.h
  22.  
  23. >and 
  24.  
  25. >cc -D SOURCE=source_b.h
  26.  
  27. >includes source_b.h, (this doesn't seem to work with the xlc compiler)
  28.  
  29. As far as I know, there's no portable way to do this directly. However, 
  30. you could always use the following when the list of files you might want 
  31. is small and well-defined:
  32.  
  33. #ifdef SOURCE_A
  34. #include "source_a.h"
  35. #endif
  36. #ifdef SOURCE_B
  37. #include "source_b.h"
  38. #endif
  39. ...
  40.  
  41. Though in this case, I'd also want some mechanism for recognizing if NO 
  42. file was given and either aborting or otherwise notifying the creator of 
  43. the problem.
  44.  
  45.   Bob
  46.  
  47.  
  48.